package com.qingzhuge.common.jwt.security.impl;

import com.qingzhuge.common.jwt.security.DataSecurityAction;
import org.springframework.util.Base64Utils;

import static com.qingzhuge.common.Constants.DEFAULT_CHARSET;

public class Base64SecurityAction implements DataSecurityAction {

    @Override
    public String doAction(String beProtected) {
        return Base64Utils.encodeToString(beProtected.getBytes(DEFAULT_CHARSET));
    }

    @Override
    public String unlock(String securityCode) {
        byte[] bytes = Base64Utils.decodeFromString(securityCode);
        return new String(bytes);
    }
}